<template>
  <div>
  <a-card :bordered="false" class="mb15 searchCard">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="名称">
              <j-input placeholder="请输入名称" v-model="queryParam.name"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="别名">
              <j-input placeholder="请输入别名" v-model="queryParam.alias"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    </a-card>
    <a-card :bordered="false">
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
             <a>删除</a>
          </a-popconfirm>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleTest(record)">功能测试</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <sys-identity-modal ref="modalForm" @ok="modalFormOk"></sys-identity-modal>
  </a-card>
  </div>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { KsListMixin } from '@/mixins/KsListMixin'
  import SysIdentityModal from './modules/SysIdentityModal'
  import JSuperQuery from '@/components/ksource/JSuperQuery.vue'
  import { getAction } from '@api/manage'

  export default {
    name: 'SysIdentityList',
    mixins:[KsListMixin, mixinDevice],
    components: {
      SysIdentityModal,
      JSuperQuery,
    },
    data () {
      return {
        description: '流水号管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'名称',
            dataIndex: 'name'
          },
          {
            title:'别名',
            dataIndex: 'alias'
          },
          {
            title:'规则',
            dataIndex: 'regulation'
          },
          {
            title:'生成类型',
            dataIndex: 'gentype_dictText'
          },
          {
            title:'流水号长度',
            dataIndex: 'nolength'
          },
          {
            title:'初始值',
            dataIndex: 'initvalue'
          },
          {
            title:'步长',
            dataIndex: 'step'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        isorter:{
          column: 'id',
          order: 'desc',
        },
        url: {
          list: "/system/sysIdentity/list",
          delete: "/system/sysIdentity/delete",
          deleteBatch: "/system/sysIdentity/deleteBatch",
          test: "/system/sysIdentity/test"
        }
      }
    },
    created() {
    },
    computed: {
    },
    methods: {
      handleTest(record) {
        let closeLoading = this.$message.loading('生成中...', 0)
        getAction(this.url.test, {
          alias: record.alias
        }).then(res => {
          if (res.success) {
            this.$info({
              title: '流水号功能测试',
              okText: '确定',
              content: '生成结果：' + res.result
            })
          } else {
            this.$message.warn(res.message)
          }
        }).finally(() => {
          closeLoading()
        })
      }
    }
  }
</script>

